package com.blz.flare.crawler;

import java.beans.XMLDecoder;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * Main class for temporary testing
 */
public class Main {
	public static void main(String[] args) {
		if (args.length != 1 || "-h".equals(args[0])) {
			System.out.println("java com.blz.flare.crawler.Main /path/configfile");
			System.exit(0);
		}
		File f = new File(args[0]);
		if (! f.exists() && f.canRead()) {
			System.out.println("The config file \"" + args[0] + "\" does not exist or cannot be read.");
			System.exit(1);
		}
		try {
			XMLDecoder d = new XMLDecoder(new BufferedInputStream(new FileInputStream(f)));
			CrawlerConfig config = (CrawlerConfig)d.readObject();
			d.close();
			Crawler crawler = new Crawler(config);
			crawler.start();
			try {
				crawler.join();
			} catch (InterruptedException e) {}
		} catch (IOException e) {
			System.out.println("Error reading config from file \"" + args[0] + "\":");
			e.printStackTrace();
			System.exit(1);
		}
	}
}
